﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PrinterMonitorSvc.Ext
{
    /// <summary>
    /// List扩展方法
    /// </summary>
    public static class ListExt
    {
        /// <summary>
        /// 拆分集合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        /// <param name="num">拆分数量</param>
        /// <returns></returns>
        public static List<List<T>> partition<T>(this List<T> value, int num)
        {
            List<List<T>> result = new List<List<T>>();
            for (int i = 0; i < value.Count; i += num)
            {
                result.Add(value.Skip(i).Take(num).ToList());
            }
            return result;
        }
    }
}
